package com.studentmanagement.util;

import java.util.List;

public class PageBean<T> {
    private int pageNumber;    // 当前页码
    private int pageSize;      // 每页显示的记录数
    private int totalRecords;  // 总记录数
    private int totalPages;    // 总页数
    private List<T> data;      // 当前页的数据
    private String sortField;  // 排序字段
    private String sortOrder;  // 排序方式（升序/降序）
    
    public PageBean() {
    }
    
    public PageBean(int pageNumber, int pageSize) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.sortOrder = "ASC";
    }
    
    public int getPageNumber() {
        return pageNumber;
    }
    
    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }
    
    public int getPageSize() {
        return pageSize;
    }
    
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    
    public int getTotalRecords() {
        return totalRecords;
    }
    
    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
        // 计算总页数
        this.totalPages = (totalRecords % pageSize == 0) ? 
                          (totalRecords / pageSize) : 
                          (totalRecords / pageSize + 1);
    }
    
    public int getTotalPages() {
        return totalPages;
    }
    
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
    
    public List<T> getData() {
        return data;
    }
    
    public void setData(List<T> data) {
        this.data = data;
    }
    
    public String getSortField() {
        return sortField;
    }
    
    public void setSortField(String sortField) {
        this.sortField = sortField;
    }
    
    public String getSortOrder() {
        return sortOrder;
    }
    
    public void setSortOrder(String sortOrder) {
        this.sortOrder = sortOrder;
    }
    
    // 判断是否有上一页
    public boolean isHasPreviousPage() {
        return pageNumber > 1;
    }
    
    // 判断是否有下一页
    public boolean isHasNextPage() {
        return pageNumber < totalPages;
    }
}

